{layout name="layout" /}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    <a href="{:url('admin/index/index')}"> 首页</a>
    <span class="c-gray en">&gt;</span>
    <a href="{:url('admin/template_detail/index')}">内容模板管理</a>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
        href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="Hui-article">
    <article class="cl pd-20" style="min-width: 900px;">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" href="{:url('template_detail/info')}">
                    <i class="Hui-iconfont">&#xe600;</i> 添加模板</a>
            </span>
            <span class="r">共有数据：<strong id="total">{notempty name="list"}{$list|count}{else/}0{/notempty}</strong>
                条</span>
        </div>
        <div id="edatalist">
            <table class="table table-border table-bordered table-bg">
                <thead>
                    <tr class="text-c">
                        <th width="80px;">ID</th>
                        <th>模板标题</th>
                        <th width="120px;">排序</th>
                        <th width="200px;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $list as $val}
                    <tr class="text-c va-m">
                        <td>{$val.id}</td>
                        <td class="text-l">
                            {$val.title}
                        </td>
                        <td>{$val.sort}</td>
                        <td class="td-manage">
                            <a href="{:url('template_detail/info', ['id'=>$val.id])}" title="修改">修改</a>
                            <a href="javascript:void(0);" title="删除" class="ml-10"
                                onClick="del(this,'{$val.id}')">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
        </div>
    </article>
</div>
<script>
    function del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post('delete', {
                'id': id
            }, function (data) {
                if (data.code == 1) {
                    console.log($(obj));
                    $(obj).parents("tr").remove();
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 2000
                    });
                    return false;
                }
            }, 'json');
        });
    }
</script>